<?php
if(!defined('IN_BSTO')){ die('[ERROR] You cannot load this page directly !!!'); }

Class DetailController Extends BaseController
{

    public function index($id = 1) {   
    	$db = $this->registry->db; 
  		$bookDetailContent = $this->registry->template->getBookDetailContent($db->get('bookManager')->getById($id), $db->get('bookManager')->getRelatedBooks($id));
        $book = $db->get('bookManager')->getById($id); 
        $headContent = '                  
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta property="og:title" content="{bookName}" />
            <meta property="og:type" content="book" />
            <meta property="og:url" content="{statisticURL}detail/{id}" />
            <meta property="og:image"
            	content="{statisticURL}views/images/thumbnail/{bookThumbnail}" />
            <meta property="og:site_name" content="Book Store" />
            <meta property="og:description" content="{bookContent}" />
            <meta property="fb:admins" content="1416293132" />';
            
        $title = $db->get('bookManager')->getById($id)->get('title');
        $tags = array('bstoHead'=> $headContent,
                     'bookName'    	=> $book->get("title"),
			         'bookThumbnail'=> $book->get("thumbnail"),
				 	 'id'			=> $book->get("nid"),
                     'bookContent'  => $book->get("summary"));
    	$user = $this->registry->db->get('userManager')->getCurrentUser();
    	
        if($user != null){
        	$tags['login'] = '<li id="login"><span> Hello, '. $user->get('username').'</span><a href="{bstoRootPath}logout">Logout</a></li>';	
        }else{
        	$tags['login'] = '<li id="login"><a href="{bstoRootPath}login">Login</a></li>';
        }             
        $output = $this->registry->template->getPageContent('index', $title, $bookDetailContent, $tags);               
        echo $output;      
    }

}

?>